// 修改后的 deploy.js（兼容 ethers v6）
async function main() {
    const [deployer] = await ethers.getSigners();
    console.log("Deploying contracts with the account:", deployer.address);
  
    const Greeter = await ethers.getContractFactory("Greeter");
    
    // 使用新API部署
    const greeter = await Greeter.deploy("Hello, Hardhat!");
    
    // 等待合约部署确认（ethers v6+）
    await greeter.waitForDeployment();
    
    // 获取合约地址
    const contractAddress = await greeter.getAddress();
    console.log("Greeter deployed to:", contractAddress);
  }
  
  main()
    .then(() => process.exit(0))
    .catch((error) => {
      console.error(error);
      process.exit(1);
    });